﻿using System.Text;

using RWG.Silverlight.Components.SPDiscussion;
using System.Collections.ObjectModel;
namespace RWG.Silverlight.SPDiscussion.ViewModels
{
    public class MainPageVM
    {
        public string ListID { get; set; }

        private ObservableCollection<DiscusssionManager.DiscussionHeader> discussions;
        public ObservableCollection<DiscusssionManager.DiscussionHeader> Discussions
        {
            get { return discussions; }
            set { discussions = value; }
        }
        private ObservableCollection<DiscusssionManager.DiscussionMessage> messages;
        public ObservableCollection<DiscusssionManager.DiscussionMessage> Messages
        {
            get { return messages; }
            set { messages = value; }
        }
  
        public MainPageVM()
        {
            discussions = new ObservableCollection<DiscusssionManager.DiscussionHeader>();

            messages = new ObservableCollection<DiscusssionManager.DiscussionMessage>();

        }
        const string MessageHeaderFormat =
            @"<b>From:&nbsp</b>{0}<br/>
<b>Posted:&nbsp</b>{1}<br/>
<b>Subject:&nbsp</b>{2}<br/>";
        public string GetMessageBody(DiscusssionManager.DiscussionHeader discussionHeader)
        {
            StringBuilder Body = new StringBuilder();

            Body.Append(string.Format(MessageHeaderFormat, discussionHeader.Author.PersonName, discussionHeader.DiscussionLastUpdated, discussionHeader.Title));
            Body.Append(discussionHeader.Body);
            return Body.ToString();

        }
        public string GetMessageBody(DiscusssionManager.DiscussionMessage discussionMessage)
        {
            StringBuilder Body = new StringBuilder();
            Body.Append(string.Format(MessageHeaderFormat, discussionMessage.Author.PersonName, discussionMessage.DiscussionLastUpdated," da title:"));
            Body.Append(discussionMessage.Body);
            
            return Body.ToString();

        }
    }
}
